//
//  STPerfectInfoViewController.m
//  赛拓
//
//  Created by 王磊 on 8/13/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STPerfectInfoViewController.h"

@interface STPerfectInfoViewController ()<UITextFieldDelegate>

@property (nonatomic ,strong) UITextField *tf;

@end

@implementation STPerfectInfoViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.tf becomeFirstResponder];
    
}
- (void)initSubviews {
    [super initSubviews];
    
    [self initTextField];
    
    [self initCompleteBtn];
}
- (void)initTextField {
    
    CGFloat margin = 20 * ST_RATE;
    
    CGFloat height = 50;
    
    UITextField *tf = [[UITextField alloc]init];
    
    self.tf = tf;
    
    [self.view addSubview:tf];
    
    tf.delegate = self;
    
    tf.frame = CGRectMake(margin,margin , ST_SCREEN_WIDTH - margin * 2, height);
}
- (void)initCompleteBtn {
    CGFloat margin = 20 * ST_RATE;
    
    CGFloat height = 50;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self.view addSubview:btn];
    
    [btn addTarget:self action:@selector(complete) forControlEvents:UIControlEventTouchUpInside];
    
    btn.frame = CGRectMake(margin , CGRectGetMaxY(self.tf.frame), ST_SCREEN_WIDTH - margin * 2, height);
    
    [btn setTitle:@"完成" forState:UIControlStateNormal];
    [btn setTitle:@"完成" forState:UIControlStateHighlighted];
    
}
- (void)complete {
    [self.tf resignFirstResponder];
    
    [self.navigationController popViewControllerAnimated:true];
    
    if (self.tf.hasText) {
        
        self.block(nil,self.tf.text,nil);
    }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [self complete];
    
    return true;
}



@end
